package servermain.restful;

import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.hysoft.cxf.ws.restful.RestHelloWorld;

public class ServerMain {
	private static AbstractApplicationContext cxt;

	public static void main(String[] args) {
		cxt = new ClassPathXmlApplicationContext("applicationContext.xml");
		RestHelloWorld restHelloWorld = (RestHelloWorld) cxt.getBean("restHelloWorldImpl");
		JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
		sf.setResourceClasses(RestHelloWorld.class);
        sf.setResourceProvider(RestHelloWorld.class, 
            new SingletonResourceProvider(restHelloWorld));
		sf.setAddress("http://localhost:9999/");
		sf.getInInterceptors().add(new LoggingInInterceptor());
		sf.getOutInterceptors().add(new LoggingOutInterceptor());
		sf.create();
		System.out.println("*******暴露成功********");
	}
}
